#!/bin/bash

if [ ! "$1" = "" ]
then
    input_dir=$1
else
    input_dir=.
fi

cd "$input_dir"
find . -type f | grep -v "`basename $0`" | grep -v ".DS_Store" | while read line
do
    timestamp=`stat -t %Y%m%d%H%M%S  "$line" | awk '{print $10}' | sed -e "s/\"//g"`
    bname=`basename "$line"`

    if echo "$bname" | grep -qv "^$timestamp"
    then
        echo "mv $line ${timestamp}-${bname}"
        mv "$line" "${timestamp}-${bname}"
    else 
        echo "Ignoring $line"
    fi
done
